package commands;

import bot.CommandBot;

import modLoader.ModLoader;


public class Lmod implements Command {

	public String getCommandName() {
		return "lmod";
	}

	public boolean execCommand(String channel, String sender, String login,
			String hostname, String message, CommandBot bot) {
		if(message.startsWith(" ")) {
			loadMod(channel, message, bot);
			return true;
		}
		return false;
	}

	private void loadMod(String channel, String message, CommandBot bot) {
		String mod = message.trim();
		try {
			mod = mod.substring(0, 1).toUpperCase() + mod.substring(1);
		} catch (IndexOutOfBoundsException i) {
			return;
		}
		Command c = ModLoader.newCommandInstance(mod);
		((CommandBot) bot).getCommands().put(mod, c);
		bot.sendMessage(channel, mod + "-Module loaded", true);
	}

	@Override
	public boolean execCommand(String sender, String login, String hostname,
			String message, CommandBot bot) {
		if (message.startsWith(" ")) {
			loadMod(sender, message, bot);
			return true;
		}
		return false;
	}
}
